package com.dudu.log.smsLog.dao;

import java.sql.Connection;
import java.util.List;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;

import core.CoreDao;
import core.db.DBConnectionUtil;

public class SmsLogDao {
    /**
     * 查询条数（分页用）
     * 
     * @param paramSql
     * @return
     */
    public int getTotalAcount(CoreDao dao, String paramSql) {
	if (StringUtils.isNotBlank(paramSql)) {
	    paramSql = " and " + paramSql;
	}
	Connection con = null;
	int result = -1;
	try {
	    con = DBConnectionUtil.getDBConnection("emate1");
	    StringBuffer sql = new StringBuffer(" select count(1) as totalAcount " + " from t_sms_info" + " where 1=1  " + paramSql);

	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] {});

	    JSONObject obj = list.get(0);
	    result = (Integer) obj.get("totalAcount");

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return result;
    }

    /**
     * 查询数据（分页）
     * 
     * @param paramSql
     * @param pageSql
     * @return
     */
    public List<JSONObject> queryAll(CoreDao dao, String paramSql, String pageSql) {
	Connection con = null;
	List<JSONObject> result = null;
	if (StringUtils.isNotBlank(paramSql)) {
	    paramSql = " and " + paramSql;
	}
	try {
	    con = DBConnectionUtil.getDBConnection("emate1");
	    StringBuffer sql = new StringBuffer(" select *  from t_sms_info where 1=1" + paramSql + " order by create_time desc " + pageSql);
	    result = dao.serviceJsonSql(con, sql.toString(), new Object[] { null });
	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return result;
    }
}
